#include "GL/glew.h"
#include "LoadShader.h"
#include "utility.h"
#include "vmath.h"
#include "GLFW/glfw3.h"
#include <functional>
#include <vector>
#include "RollPath.h"

using std::vector;

void mousePositionCallback(GLFWwindow* window, double xpos, double ypos)
{

}

void mouseButtonCallback(GLFWwindow* window, int button, int action, int mods)
{

}

int getViewWidth();
int getViewHeight();




GLuint program;

RollPath* rollpath = nullptr;
float pathLength = 40;
float radius = 4;
float step = 0.2f;

float unfoldTime = 3.f;
float startTime = 1.f;


bool init()
{
	ShaderInfo si[] = { { GL_VERTEX_SHADER, "Shader.vert" },{ GL_FRAGMENT_SHADER, "Shader.frag" },{ GL_NONE, nullptr } };
	program = LoadShade(si);
	
	rollpath = RollPath::create(pathLength, radius, step);



	glClearColor(0.0f, 0.05f, 0.05f, 1.0f);
	return true;
}

inline float rad2deg(float rad) 
{
	return float(rad / M_PI * 180.f);
}

void Display(double time)
{
	glClear(GL_COLOR_BUFFER_BIT);
	
	float currentTime = (float)time - startTime;
 	// currentTime = 10;
	if (currentTime < 0.0001) {
		return;
	}

	if (currentTime > unfoldTime + 2) {
		startTime = (float)time +1.f;
		return;
	}
	else if (currentTime > unfoldTime) {
		currentTime = unfoldTime;
	}

	float percentage = currentTime / unfoldTime;

	rollpath->draw(program, percentage);


}


void onClose()
{
	if (rollpath != nullptr) {
		delete rollpath;
	}
	glDeleteProgram(program);
}

